﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lesson01
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            Label lblFeedbackLabel = new Label();
            TextBox txtInputTextBox = new TextBox();
            Button btnSubmitButton = new Button();

            lblFeedbackLabel.ID = "FeedbackLabel";
            lblFeedbackLabel.Text = "Please type your name:";

            btnSubmitButton.ID = "SubmitButton";
            btnSubmitButton.Text = "Submit";

            txtInputTextBox.ID = "InputTextBox";

            btnSubmitButton.Click += new EventHandler(btnSubmitButton_Click);

            this.Panel1.Controls.Add(lblFeedbackLabel);
            this.Panel1.Controls.Add(txtInputTextBox);
            this.Panel1.Controls.Add(btnSubmitButton);
        }

        void btnSubmitButton_Click(object sender, EventArgs e)
        {
            Button btnSubmitButton = sender as Button;

            btnSubmitButton.Text = "Submit again";

            Label lblFeedbackLabel = this.FindControl("FeedbackLabel") as Label;
            TextBox txtInputTextBox = this.FindControl("InputTextBox") as TextBox;

            //Update controls
            lblFeedbackLabel.Text = string.Format("Hi, {0}", txtInputTextBox.Text);
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}